package com.dthunder.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/*
 * 
 *   <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
    <property name="hibernate.connection.url">jdbc:db2://127.0.0.1:50000/testDb</property>
    <property name="hibernate.connection.username">db2inst1</property>
    <property name="hibernate.connection.password">000000</property>
 * 
 */
public class DbConnection {
	public static Connection getConnection() {
		Connection conn=null;
		
		try {
			Class.forName("com.ibm.db2.jcc.DB2Driver");
			conn = DriverManager.getConnection("jdbc:db2://127.0.0.1:50000/testDb", "db2inst1", "000000");
			
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return conn; 
	}
	
	public static  boolean  executeSQL(String sql) {
		Connection conn = getConnection();
		try {
			Statement stmt = conn.createStatement();
			return stmt.execute(sql);
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("execute "+sql+" fail~");
			return false;
		}		
	}

}
